package com.xiaoma.bingo.utils;

import java.util.Map;

import com.dexcoder.commons.utils.NameUtils;
import com.dexcoder.commons.utils.StrUtils;
import com.dexcoder.dal.build.AutoField;
import com.dexcoder.dal.handler.MappingHandler;

public class MyMappingHandler implements MappingHandler{

    @Override
    public String getTableName(Class<?> entityClass, Map<String, AutoField> fieldMap) {
        return NameUtils.getUnderlineName(entityClass.getSimpleName());
    }

    @Override
    public String getPkFieldName(Class<?> entityClass) {
        return "id";
    }

    @Override
    public String getPkColumnName(Class<?> entityClass) {
        return "id";
    }

    @Override
    public String getColumnName(Class<?> entityClass, String fieldName) {
        return NameUtils.getUnderlineName(fieldName);
    }

    @Override
    public String getPkNativeValue(Class<?> entityClass, String dialect) {
        if (StrUtils.equalsIgnoreCase(dialect, "oracle")) {
            //获取序列就可以了，默认seq_加上表名为序列名
            String tableName = this.getTableName(entityClass, null);
            return String.format("SEQ_%s.NEXTVAL", tableName);
        }
        return null;
    }

}
